package apps.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.web.servlet.ModelAndView;

import webframe.common.helper.ControllerHelper;
import apps.web.controller.base.MyBaseCommandController;
import apps.web.model.User;

public class UserSearchController extends MyBaseCommandController {

	@Override
	protected ModelAndView handleInner(HttpServletRequest request,
			HttpServletResponse response, Object command) {
		User cuser = (User) command;
		DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
		ControllerHelper.addEqualRestrictions(criteria, "id", cuser.getId());
		ControllerHelper.addLikeRestrictions(criteria, "username", cuser
				.getUsername());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("page", ControllerHelper.queryPagination(request, criteria));
		map.put("user", cuser);
		return new ModelAndView("UserSearch.jsp", "map", map);
	}
}
